﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMTPAPI.Interfaces;
using System.Net.Mail;
using System.Web;

namespace SMTPAPI.InterfaceImplementation
{
    public class SenderInfo:ISenderInfo
    {
        public MailMessage CreateMailBasicFormat(string senderAddress, string subject, string body, bool isHtmlBody, string mailHeaderPath)
        {
            MailMessage mailMessage = new MailMessage();
            mailMessage.From = new MailAddress(senderAddress);
            if (isHtmlBody)
            {

                CreateHTMLMailBody(body, mailHeaderPath, mailMessage, subject);
            }
            else
            {

                mailMessage.Subject = subject;
                mailMessage.Body = body;
            }

            return mailMessage;
        }

        private void CreateHTMLMailBody(string body, string mailHeaderPath, MailMessage mailMessage, string subject)
        {
            mailMessage.Subject = subject;
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = "<html><head><title>" + HttpUtility.HtmlEncode(subject) + "</title></head><body>" +
                "<img src=" + mailHeaderPath + "/>" + "<p>" +
                HttpUtility.HtmlEncode(body) + "</p>" + "</body></html>";
        }
    }
}
